#include "progressbar.h"
#include <time.h>
#include <stdlib.h>
#define FILESIZE 1024*1024*1024
void download(callback_t cb) // 回调函数
{
    srand(time(NULL)^1023);
    int total = FILESIZE;
    while(total>0)
    {
        usleep(100000);
        int speed = rand()%(1024*1024*10);
        total -= speed;
        if(total < 0) 
            total = 0;
        //int download = FILESIZE - total;
        //double rate = (download*1.0/(FILESIZE))*100.0;
        double rate =100.0*(FILESIZE - total)/(FILESIZE);//(FILESIZE)的()保证了宏展开的时候运算顺序不会发生变化
        cb(rate);
    }
}

int main()
{
    //progress();
    download(progress_flush);
    printf("\n");
    return 0;
}
